console.log('初始化开始');

import React from 'react';
import ReactDOM from 'react-dom';
import { Root } from './js/app.root';
import { Login } from './js/app.login';

/**
 * 在body里边插入容器
 *
 */
function createBody() {
    const app = document.createElement('div');
    app.setAttribute('id','app');
    document.body.appendChild(app);
}



/**
 * 创建全局变量并启动
 *
 */
function createGlobalVariable(){
    let gv = {};
    let launch = {
        startHref: location.href,
        startOrigin:location.origin,
    };
    gv.launch = launch;
    createBody();
    function insteadLoginToRoot(params) {
        ReactDOM.unmountComponentAtNode(document.querySelector('#app'));
        ReactDOM.render(        
            <Root />,
            document.querySelector('#app')
        )
    }
    if(gv.user){
        // 进入面板页面
        ReactDOM.render(        
            <Root />,
            document.querySelector('#app')
        )
    }else{
        // 需要进行登陆
        const loginElm = <Login loginSucess={insteadLoginToRoot}/>;
        ReactDOM.render(        
            loginElm,
            document.querySelector('#app')
        )
    }
}


createGlobalVariable();

